<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="perm" uri="/WEB-INF/tld/perm.tld"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<script>var ctx="${ctx}";</script>
<style>
.row input{
	margin-top: 5px;
}
.row select{
	margin-top: 5px;
}
</style>
<div class="form-horizontal" role="form" >
	<input id="id" value="${sysResource.id}"  type="hidden"/>
	<div class="form-group">
 	    <label for="inputEmail1" class="col-md-3 col-sm-3 control-label">资源名称:</label>
        <div class="col-md-9">
        	<input id="name" value="${sysResource.name}"  data-check="require:true,code:input1,minlen:2,maxlen:20, message:2-20中文或字母" type="text" placeholder="资源名称" class="form-control" name="name"/>
        </div>
    </div>
    <div class="form-group">
 	    <label for="inputEmail1" class="col-md-3 col-sm-3 control-label">资源描述:</label>
        <div class="col-md-9">
        	<input id="remark" value="${sysResource.remark}"  type="text" placeholder="资源描述" class="form-control" name="remark"/>
        </div>
    </div>
    <div class="form-group">
 	    <label for="inputEmail1" class="col-md-3 col-sm-3 control-label">资源URI:</label>
        <div class="col-md-9">
        	<input id="url" value="${sysResource.url}"  type="text" placeholder="资源URI" class="form-control" name="url"/>
        </div>
    </div>
    <div class="form-group">
 	    <label for="inputEmail1" class="col-md-3 col-sm-3 control-label">所属资源:</label>
        <div class="col-md-9">
        	<select id="resources_parent" placeholder="选择所属资源" class="form-control chosen-select " tabindex="4">
				<option value="" >选择所属资源</option>
			</select>
        </div>
    </div>
    <c:if test="${sysResource.id == null}">
	    <div class="form-group">
	 	    <label for="inputEmail1" class="col-md-3 col-sm-3 control-label">所属角色:</label>
	        <div class="col-md-9">
	        	<select id="chosen-select3" data-placeholder="选择所属角色" multiple class="form-control input-sm chosen-select " tabindex="4">
					<option value="" >选择所属角色</option>
				</select>
	        </div>
	    </div>
    </c:if>
	<div class="form-group">
 		<label for="inputEmail1" class="col-md-3 col-sm-3 control-label">是否是菜单:</label>
        <div class="col-md-9">
        	<div class="form-inline" >
        	<div class="checkbox">
                 <label><input type="radio"  name="isMenu" value="1"  <c:if test="${sysResource.isMenu==1}">checked=""</c:if>> <i></i>是</label>
             </div>
             <div class="checkbox">
                 <label><input type="radio"  name="isMenu" value="2" <c:if test="${sysResource.id == null}">checked=""</c:if> <c:if test="${sysResource.isMenu==2}">checked=""</c:if>> <i></i>否</label>
             </div>
            </div>
        </div>
    </div>
</div>

<script>
	$("#chosen-select3").chosen({ width: '100%' });
	$("#resources_parent").chosen({ width: '100%' });


	var resourcesParentId="${sysResource.parentId}";
	
	var roleIds=[];
	var roleIds_="${sysResource.roleIds}";
	if(roleIds_!=null && roleIds_!=""){
		roleIds=roleIds_.split(",");
	}

	 $.ajax({  
		url:'${ctx}/resource/list',  		 					
		data:{
			sortNo:$("#sortNo").val(),							
			status:0							
		},   
		type: 'POST',
		dataType:'json',  
		success:function(response){
			if(response.code==0){
				var html=[];
				var data=response.data||[];
				for(var i=0;i<data.length;i++){
					html.push('<option value="'+data[i].id+'" ');
					if(resourcesParentId===data[i].id){
						html.push('selected="selected"'); 
					}
					html.push('>'+data[i].name+'</option>');
				}
				$("#resources_parent").append(html.join(""));
				$("#resources_parent").val(resourcesParentId);
				$("#resources_parent").trigger("chosen:updated");
			}
		}  
     });
	 
	 $.ajax({  
		url:'${ctx}/role/list',  		 					
		data:{
			sortNo:$("#sortNo").val(),							
			status:0							
		},   
		type: 'POST',
		dataType:'json',  
		success:function(response){
			if(response.code==0){
				var html=[];
				var data=response.data||[];
				for(var i=0;i<data.length;i++){
					html.push('<option value="'+data[i].id+'">'+data[i].name+'</option>');
				}
				$("#chosen-select3").append(html.join(""));
				$("#roleIds").val(roleIds);
				$("#chosen-select3").trigger("chosen:updated");
			}
		}  
     });
</script>
